use strict;
use warnings;

use File::Spec;
use FindBin;
use lib File::Spec->catfile($FindBin::RealBin, qw/.. lib/);
use Test::More;

use Lingua::EN::WSD::WebBased::Seeder::DmozLabel;
use Lingua::EN::WSD::WebBased::Seeder::WordNetSense;

use Lingua::EN::WSD::WebBased::Utils;

my $wn_path     = File::Spec->catfile($FindBin::RealBin, qw/.. data wn21/);
my $dmoz_path   = File::Spec->catfile($FindBin::RealBin, qw/.. data dmoz.eng.db/);

my $wn      = eval { load_wordnet($wn_path) };
my $dmoz    = eval { load_dmoz_structure_db($dmoz_path) };

plan skip_all => 'WordNet or dmoz structure DB not loaded' if $@;

plan tests => 5;

my $s4dl = new Lingua::EN::WSD::WebBased::Seeder::DmozLabel(
    wordnet             => $wn,
    dmoz_structure_db   => $dmoz,
    sort_seeds          => 1
);

my $s4wns = new Lingua::EN::WSD::WebBased::Seeder::WordNetSense(
    wordnet             => $wn,
    sort_seeds          => 1
);

sub test_gen_seeds {

    my ($seeder, $label, $seeds) = @_;
    is_deeply [@{$seeder->gen_seeds($label)}], [sort @$seeds],
        "gen_seeds: $label";

}

sub test_gen_queries {

    my ($seeder, $label, $queries) = @_;
    is_deeply [@{$seeder->gen_queries($label)}], [@$queries],
        "gen_queries: $label";

}

test_gen_seeds $s4dl, 'Top/Business/Jobs',
[qw/association directory medium news regional resource/];

test_gen_queries $s4dl, 'Top/Business/Jobs',
['"Jobs" AND ( "association" OR "directory" OR "medium" OR "news" OR '.
 '"regional" OR "resource" )'];

$s4wns->including_syns(0);

test_gen_seeds $s4wns, 'bike#n#1',
['minibike', 'motor vehicle', 'motorcycle', 'mudguard', 'trail bike'];

$s4wns->including_syns(1);

test_gen_seeds $s4wns, 'bike#n#1',
['automotive vehicle', 'dirt bike', 'minibike', 'motor vehicle', 
 'motorbike', 'motorcycle', 'mudguard', 'scrambler', 'splash guard', 
 'splash-guard', 'trail bike'];

$s4wns->including_syns(0);

test_gen_queries $s4wns, 'bike#n#1',
['"bike" AND ( "minibike" OR "motor vehicle" OR "motorcycle" OR "mudguard" '.
 'OR "trail bike" )'];
